//
//  ToneMapperController.h
//  ToneMapper
//
//  Created by Andrey on 03/02/2009.
//  Copyright 2009 Karma Software. All rights reserved.
//

#import <Cocoa/Cocoa.h>
#import "KImage.h"
#import "KPixel.h"

@class ToneMapperView;
@class CurvesView;
@class HistogramView;
@class KSegmentationMap;
@class K2DSegmentationMap;
@class ChromaticityHistogramView;

@interface ToneMapperController : NSObject 
{
	/* Interface Builder outlets */
	/* Main window */
	IBOutlet ToneMapperView* mainView;
	IBOutlet NSScrollView* scrollView;
	IBOutlet NSWindow* window;
	
	/* Histrogram window */
	IBOutlet NSWindow* histogramWindow;
	IBOutlet HistogramView* histogramView;
	IBOutlet NSTextField* meanLabel;
	IBOutlet NSTextField* varianceLabel;
	IBOutlet NSComboBox* histogramChannelComboBox;
	IBOutlet NSButton* cumulativeHistogramCheckbox;
	
	/* Channels window */
	IBOutlet NSWindow* channelsWindow;
	IBOutlet NSComboBox* channelComboBox;
	
	/* Curves window */
	IBOutlet NSWindow* curvesWindow;
	IBOutlet CurvesView* curvesView;
	
	/* Composite equalization window */
	IBOutlet NSWindow* compositeEqualizationWindow;
	IBOutlet NSSlider* luminanceEqualizationSlider;
	IBOutlet NSSlider* rgbEqualizationSlider;
	IBOutlet NSSlider* hueEqualizationSlider;
	
	/* Segmentation window */
	IBOutlet NSWindow* segmentationWindow;
	IBOutlet NSComboBox* channelForSegmentationComboBox;
	IBOutlet NSTextField* segmentCountTextField;
	
	/* Chromaticity histogram window */
	IBOutlet NSWindow* chromaticityHistogramWindow;
	IBOutlet ChromaticityHistogramView* chromaticityHistogramView;
	IBOutlet NSComboBox* chromaticityHistogramChannelComboBox;
	
	/* Data */
	KImage* currentImage;
	KImage* displayBuffer;
	
	/* Segmentation */
	KSegmentationMap* segmentationMap;
	K2DSegmentationMap* chromaticitySegmentationMap;
	Boolean useChromaticityForSegmentation;
	enum KImageChannel channelForSegmentation;

	/* Histogram */
	enum KImageChannel displayedHistogramChannel;
	Boolean displayCumulativeHistogram;
	enum KChromaticityChannel displayedChromaticityHistogramChannel;
}

@property (readonly) KImage* currentImage;
@property (readonly) KImage* displayBuffer;
@property (readonly) KSegmentationMap* segmentationMap;
@property (readonly) K2DSegmentationMap* chromaticitySegmentationMap;
@property (readonly) enum KImageChannel channelForSegmentation;
@property (readonly) enum KImageChannel displayedHistogramChannel;
@property (readonly) enum KChromaticityChannel displayedChromaticityHistogramChannel;
@property (readonly) Boolean useChromaticityForSegmentation;
@property (readonly) Boolean displayCumulativeHistogram;

- (IBAction) openDocument: (id) sender;
- (IBAction) saveDocument: (id) sender;
- (IBAction) restoreCurrentImageFromBackup: (id) sender;

- (IBAction) showHistogramWindow: (id) sender;
- (IBAction) changeDisplayedHistogramChannel: (id) sender;
- (IBAction) changeHistogramType: (id) sender;

- (IBAction) showChannelsWindow: (id) sender;
- (IBAction) changeChannel: (id) sender;

- (IBAction) showCurvesWindow: (id)sender;
- (IBAction) applyCurves: (id)sender;

- (IBAction) recalibrateBrightness: (id) sender;
- (IBAction) applyEqualization: (id) sender;

- (IBAction) showSegmentationWindow: (id) sender;
- (IBAction) changeSegmentationSource: (id) sender;
- (IBAction) segmentImage: (id) sender;

- (IBAction) showCompositeEqualizationWindow: (id) sender;
- (IBAction) applyCompositeEqualization: (id) sender;

- (IBAction) applyAutoLevels: (id) sender;

- (IBAction) showChromaticityHistogramWindow: (id) sender;
- (IBAction) changeDisplayedChromaticityHistogramChannel: (id) sender;

- (id) init;
- (void) equalizeBrightnessHistogram;
- (void) equalizeHueHistogram;
- (void) equalizeRGBHistogram;
- (void) trackMouseDragging: (NSPoint)mouseLocation;
- (void) updateHistogramStatistics;
- (void) dealloc;

@end
